package com.sbj.controller;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sbj.dto.req.TransferReq;
import com.sbj.dto.res.TransferRes;
import com.sbj.entity.Transfer;
import com.sbj.service.TransferService;
import com.zmh.framework.config.BaseCommonInterface;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/27 14:39
 */
@RestController
@RequestMapping(value = "/transfer")
@AllArgsConstructor
public class TransferController implements BaseCommonInterface<TransferReq, TransferRes> {

    private final TransferService transferService;

    @Override
    public Result<String> save(@Valid TransferReq transferReq) {
        transferService.saveOrUpdate(Convert.convert(Transfer.class,transferReq));
        return Result.successResult();
    }

    @Override
    public Result<String> del(Integer id) {
        transferService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<TransferRes>> lists(TransferReq transferReq) {
        Page<TransferRes> page= transferService.lists(transferReq);
        return Result.successResult(page);
    }

    @Override
    public Result<TransferRes> findById(Integer id) {
        return Result.successResult(Convert.convert(TransferRes.class,transferService.getById(id)));
    }

    @Override
    public Result<String> batchDel(List<TransferRes> list) {
        return null;
    }
}
